package com.yiwei.ydd.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.ydd.R;
import com.yiwei.ydd.api.model.CashBackIndexModel;
import com.yiwei.ydd.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class AccountMonthAdapter extends ItemAdapter<CashBackIndexModel.DatasBean.ItemBean, AccountMonthAdapter.DefaultHolder> {


    public AccountMonthAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_account_month, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        CashBackIndexModel.DatasBean.ItemBean item = getItem(position);
        holder.txtMoney.setText(item.money + "(" + item.period + "/" + item.periods + ")");
        holder.txtTime.setText(DateTime.toDate(Long.valueOf(item.get_sdate) * 1000));
        //返现状态（-1：失败，1：完成，2：待返现）
        switch (item.status) {
            case "-1":
                holder.txtStatus.setText("失败");
                holder.txtStatus.setTextColor(0xffff4f4e);
                break;
            case "1":
                holder.txtStatus.setText("已到账");
                holder.txtStatus.setTextColor(0xff15B215);
                break;
            case "2":
                holder.txtStatus.setText("待返现");
                holder.txtStatus.setTextColor(0xffff4f4e);
                break;
        }
    }


    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_status)
        TextView txtStatus;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
